package com.cn.bukeManage.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
 * 封装时间工具类
 * @author wyw
 *
 */
public class MyDate {

	/**
	 * 
	 * @param i 0得到当前时间前一天时间 1得到当前的时间
	 * @return 返回根据请求参数的到的时间
	 */
	public static Date getTimeForMe(Integer i){
		String timeLast="17:00:00";
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
		Date date=null;
		if(i==0){
			Calendar   c   =   Calendar.getInstance();   
			c.add(Calendar.DAY_OF_MONTH, -1);  
			String mDateTime=formatter.format(c.getTime());  
			String timeFirst = mDateTime.substring(0, 11);
			//前一天时间
			StringBuffer lastDay=new StringBuffer();
			lastDay.append(timeFirst);
			lastDay.append(timeLast);
			
			try {
				 date=formatter.parse(lastDay.toString());
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}else {
			Date date2=new Date();
			String format = formatter.format(date2);
			String substring = format.substring(0,11);
			//今天时间
			StringBuffer toDay=new StringBuffer();
			toDay.append(substring);
			toDay.append(timeLast);	
			try {
				date=formatter.parse(toDay.toString());
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return date;
	}
}
